#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>

#define A_MEGABYTE (1024*1024)

int main()
{
    char *some_memory;
    int megabyte = A_MEGABYTE;
    int exit_code = EXIT_FAILURE;

    /* malloc返回的是一个void *指针, 所以我们把这个指针映射到我们需要的char *上.
     * malloc能保证返回的空间是线性的, 所以我们可以把它映射到任何类型的指针上.*/
    some_memory = (char *)malloc(megabyte);
    if(some_memory != NULL){
        sprintf(some_memory, "Hello World\n");
        printf("%s", some_memory);
        exit_code = EXIT_SUCCESS;
    }
    exit(exit_code);
}
